<?php
    require_once ('config.php');

    session_start();

/*$strLanguage = (isset($_GET['lang']) ? $_GET['lang']: 'vn');
if($strLanguage == 'en'){
    require_once ('en.php');
}else{
    require_once ('vn.php');
}*/

function tep_db_error($query, $errno, $error) { 
    die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>');
  }  
function tep_db_checkDb(){
    $link = mysql_connect(DATABASE_SERVER,DATABASE_USERNAME,DATABASE_PASSWORD);

    if(!$link){
        return false;
    }
    #echo('Connection OK.<br/>');
    $db = mysql_select_db(DATABASE_NAME);
    if(!$db){
        return false;
    }
    return true;
}

function tep_db_query($query){

    mysql_query("set names 'utf8'");
    $result = mysql_query($query) or tep_db_error($query, mysql_errno(), mysql_error());
    return $result;
}

function tep_db_insert_id() {
    return mysql_insert_id();
}
  
  function tep_db_fetch_array($db_query) {
    return mysql_fetch_array($db_query, MYSQL_ASSOC);
  }

function tep_db_close($link = 'db_link'){
    global $$link;
    return mysql_close($$link);
}

#handle for langue params
function tep_embed_langue_url($url){
    $strLanguage = (isset($_GET['langue']) ? $_GET['langue']: 'fr');
    if(strlen($_SERVER['QUERY_STRING'])==0){
        $url .= "?langue=".$strLanguage;
    }else{
        if(strpos($_SERVER['QUERY_STRING'], 'langue=')=== false){
            $url .= "&langue=".$strLanguage;   
            
        }else if(strpos($url, '?')!== false){
            $url .= "&langue=".$strLanguage;
            
        }else{
            $url .= "?langue=".$strLanguage;            
        }
    }
    return $url;
}
function tep_redirect($url){
  //  echo tep_embed_langue_url($url);
    #redirect to url page
    header("Location: ".tep_embed_langue_url($url));
   //echo "<script type=\"text/javascript\">window.location='$url';</script>";
    exit;
}

function tep_send_mail($sendName, $friend, $to, $subject='', $message='', $productlink,$strLanguage){    
    
        if($strLanguage=='en'){
            if(strlen($subject)== 0)
                $subject='Your friend wants to send you an email about this product';
    
            if(strlen($message)==0){
                $message  = "Dear ".$sendName.",\r\n";
                $message .= $friend.", your friend has participated in our Valentine's Day  Quiz and dream that you were offering
                  the product link $productlink \r\n. You are sure to please him! Welcome to our online store www.tintamar.com";
            }    
        }else{
            if(strlen($subject)== 0)
                $subject='Votre ami veut vous envoyer un e-mail sur ce produit';
    
            if(strlen($message)==0){
                $message  = "Bonjour ".$sendName.", \r\n";
                $message .= $friend.", votre ami a particip&eacute;    &agrave; notre Quiz St Valentin et r&ecirc;ve que vous lui offriez le produit en lien $productlink.\r\n" 
                    ."Vous &ecirc;tes certain de lui faire plaisir ! Bienvenue sur notre boutique en ligne www.tintamar.com";

            }
        }
    # To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    
    # Additional headers    
    $headers .= 'From: Tintamar' . "\r\n";    
    #send mail
    return mail($to,$subject, $message, $headers);        
}

?>